// // Copyright (c) 2009 All Right Reserved // // vl // // 2009-01-01 // Contains ... namespace LargoCommon.Music { using Abstract; using JetBrains.Annotations; using System.Diagnostics.Contracts; using System.Globalization; using System.Text; using System.Xml.Linq; /// /// Harmonic Change. /// public sealed class HarmonicChange : AbstractChange { #region Fields /// Harmonic motive. private HarmonicMotive harmonicMotive; #endregion #region Constructors /// /// Initializes a new instance of the class. /// [UsedImplicitly] public HarmonicChange() { } /// /// Initializes a new instance of the class. /// /// The given change. public HarmonicChange(XElement xchange) : base(xchange) { Contract.Requires(xchange != null); if (xchange == null) { return; } this.MotiveNumber = XmlSupport.ReadIntegerAttribute(xchange.Attribute("MotiveNumber")); this.MusicalLineType = MusicalLineType.Harmonic; this.ChangeType = MusicalChangeType.Harmonic; } /// /// Initializes a new instance of the class. /// /// The given bar. public HarmonicChange(int givenBar) : base(givenBar, 0, MusicalChangeType.Harmonic) { this.MusicalLineType = MusicalLineType.Harmonic; } #endregion #region Properties /// Gets or sets class of melodic part. /// Property description. public int? MotiveNumber { get; set; } /// /// Gets or sets THarmonicMotive. /// /// General musical property. public HarmonicMotive HarmonicMotive { get { var isPrepared = this.harmonicMotive != null; //// && this.tharMotive.Number == this.MotiveNumber && this.tharMotive.CoreId == this.BlockModel.MusicalCore.Id; if (isPrepared) { return this.harmonicMotive; } if (this.MotiveNumber == null) { return null; } //// if (this.BlockModel != null) { //// this.harmonicMotive = this.BlockModel.Core.HarmonicCore.GetHarmonicMotive((int)this.MotiveNumber); //// } return this.harmonicMotive ?? (this.harmonicMotive = new HarmonicMotive()); } set { Contract.Requires(value != null); this.harmonicMotive = value; this.MotiveNumber = this.harmonicMotive.Number; } } #endregion #region Public methods /// /// Clones this instance. /// /// Returns object. public override object Clone() { var tmc = new HarmonicChange(this.BarNumber) { MotiveNumber = this.MotiveNumber }; //// tmc.BlockModel = this.BlockModel; return tmc; } /// String representation of the object. /// Returns value. public override string ToString() { var s = new StringBuilder(); s.AppendFormat(CultureInfo.CurrentCulture, base.ToString()); s.Append(", Motive " + this.MotiveNumber); return s.ToString(); } #endregion } }